package cn.apthink.calendar;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import cn.apthink.utility.Util;
import lombok.Data;

@Data
public class DepartmentWorkerHelper {
	private DepartmentHelper departmentHelper;
	private List<DepartmentWorker> lstDepartmentWorker;
	
	/**
	 * 返回生产单位指定日期的人员数
	 * 
	 * @param uid
	 * @return
	 * @throws RuntimeException
	 */
	public int getDepartmentWorker(String departmentId, LocalDate current) throws RuntimeException {
		if (Util.isEmpty(lstDepartmentWorker)) {
			return departmentHelper.get(departmentId).getWorker();
		} else {
			Optional<DepartmentWorker> o = lstDepartmentWorker.stream().filter(x->{
				return x.getDepartmentId().equals(departmentId) && x.contain(current);
			}).findFirst();
			if (o.isPresent())
				return o.get().getWorker();
			else
				return departmentHelper.get(departmentId).getWorker();
		}
	}

}
